<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *积分明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'商户返利'),
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['merchname'])){
		$params['merchname like']='%'.trim($_RQ['merchname']).'%';
		$return['params']['merchname']=$_RQ['merchname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['status']!=''){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$fields=array('id','mid','star','groupid','setting','isrecommand','salecate','cateid','mobile','realname','status','jointime','accounttime','logo','merchname','upass','uname');
    $orderby='star desc, id desc';
	$total='';
	$list=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['setting']=json_decode($item['setting'],true);
			$item['jointime']=date('Y/m/d H:i:s',$item['jointime']);
			$item['setting']['paifeenew']=$item['setting']['paifeenew']?:$this->setting['pai_feerate'];
			if($item['setting']['paifee'] && $item['setting']['paifee']!=$item['setting']['paifeenew']){
				$item['ispai']=1;
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		//'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：推荐复购都可以加速公排进度！在基本设置里面设置！','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('title'=>'ID/MID','type'=>'img_string',
			'data'=>array(
				array('title'=>'ID：','name'=>'id'),
				array('title'=>'MID：','name'=>'mid')
				)
			),
			array('title'=>'商户信息_Merch','type'=>'img_string','img'=>'logo',
			'data'=>array(
				array('title'=>'名称：','name'=>'merchname'),
				array('title'=>'项目：','name'=>'salecate')
				)
			),
			array('name'=>'setting.paifee','title'=>'申请返利','type'=>'unitstring','unit'=>'%'),
			array('name'=>'setting.paifeenew','title'=>'生效返利','type'=>'unitstring','unit'=>'%'),
			array('name'=>'jointime','title'=>'入驻时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'check','title'=>'审核','show'=>array('ispai'=>1)),
		)),
		'search'=>array(
			array('name'=>'merchname','width'=>8,'title'=>'商户名称','type'=>'string'),
			array('name'=>'realname','width'=>8,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>8,'title'=>'电话','type'=>'string'),
			array('name'=>'status','width'=>8,'title'=>'状态','type'=>'select','options'=>'status'),
		)
	);
	$return['pailogtype']=$this->pailogtype;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if($post['status']==1){
			$post['setting']['paifeenew']=$post['setting']['paifee'];
		}elseif($post['status']==2){
			$post['setting']['paifee']=$post['setting']['paifeenew'];
		}
		$update=array(
			'setting'=>ijson_encode($post['setting']),
		);
		pdo_update('jy_merch_user',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_merch_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$item['setting']=json_decode($item['setting'],true);
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'审核返利',
	);
	$htmls['edit']=array(
		array('type'=>'radio','title'=>'审核','name'=>'status','options'=>'status'),
	);
	$return['htmls']=$htmls;
	$return['status']=array('待审核','审核通过','审核不通过');	
	exi($return);
}